<!DOCTYPE html>
<html>
<head>
    <title>处理授权</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
        .spinner { margin: 30px auto; width: 50px; height: 50px; border: 5px solid #f3f3f3; border-top: 5px solid #07C160; border-radius: 50%; animation: spin 1s linear infinite; }
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
    </style>
</head>
<body>
<h2>正在处理微信授权...</h2>
<div class="spinner"></div>
<p>请稍候，正在为您登录</p>

<script>
    // 解析URL参数
    function getQueryParams() {
        const params = {};
        window.location.search.substring(1).split('&').forEach(pair => {
            const [key, value] = pair.split('=');
            params[key] = decodeURIComponent(value);
        });
        return params;
    }

    // 设置cookie
    function setCookie(name, value, days) {
        let expires = "";
        if (days) {
            const date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "") + expires + "; path=/";
    }

    // 主逻辑
    document.addEventListener('DOMContentLoaded', () => {
        alert("到这边了。。中转页...")

        const params = getQueryParams();

        // 设置用户信息到cookie
        if (params.openid) {
            setCookie('openid', params.openid, 1);
            setCookie('nickname', params.nickname, 1);
            setCookie('avatar', params.avatar, 1);
        }

        // 2秒后跳转回首页
        setTimeout(() => {
            window.location.href = '/public/index.html';
        }, 2000);
    });
</script>
</body>
</html>